(function(window, document) {

	/**
	 *  数据校验
	 */
	var check = function(data) {
		if (typeof(data) === undefined || data === null || data === '' || data === undefined) return false;
		return true;
	}


	/**
	 *	XMLHttpRequest Get Html Content
	 *	@param {String} method 方法
	 *	@param {String} url 路径
	 *	@param {Bool} async 异步选项
	 */
	var loadAjax = function(method, url, async, callback) {
		var result = '';
		if (!check(method)) var method = 'GET';
		if (!check(async)) var async = false;
		var xhttp; // HTTPRequest
		if (window.XMLHttpRequest) {
			xhttp = new XMLHttpRequest();
		} else {
			xhttp = new ActiveXObject('Microsoft.XMLHTTP')
		}
		xhttp.onreadystatechange = function() {
			if (xhttp.readyState === 4 && xhttp.status === 200) {
				result = xhttp.responseText;
				callback(result);
			}
		}
		xhttp.open(method, url, async);
		xhttp.send();
	}

	var vms = new Vue({
		el: '#park',
		data: function() {
			return {
				parkList: [],
				prompt: ['室内', '室外']
			}
		},
		methods: {
			getParkList: function(index) {
				var _this = this;
				loadAjax('GET', '/getParkList?pageIndex=' + index, true, function(result) {
					var tmp = JSON.parse(result).parkList;
					_this.$set('parkList', tmp);
				});
			},
			getParkByKeyWords: function() {
				var keywords = this.$get('keywords');
				if (keywords === undefined) {
					return false;
				}
				loadAjax('GET', '/getParkListByKey?=' + keywords, true, function(result) {
					var tmp = JSON.parse(result).parkList;
					_this.$set('parkList', tmp);
				});
			}
		}
	});

	$('#layer').jqPaginator({
		totalPages: 467,
		visiblePages: 8,
		currentPage: 1,
		first: '<li class="first"><a href="javascript:void(0);">首页<\/a><\/li>',
		prev: '<li class="prev"><a href="javascript:void(0);"><i class="arrow arrow2"><\/i>上一页<\/a><\/li>',
		next: '<li class="next"><a href="javascript:void(0);">下一页<i class="arrow arrow3"><\/i><\/a><\/li>',
		last: '<li class="last"><a href="javascript:void(0);">末页<\/a><\/li>',
		page: '<li class="page"><a href="javascript:void(0);">{{page}}<\/a><\/li>',
		onPageChange: function(n) {
			vms.getParkList(n)
		}
	});
}(window, document));